package com.deschen.security.security;

import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionSignUp;
import org.springframework.stereotype.Component;

/**
 * @Author deschen
 * @Create 2019/9/6
 * @Description 用于QQ登入后获取唯一标识, 实现自动注册
 * @Since 1.0.0
 */
@Component
public class DemoConnectionSignUp implements ConnectionSignUp {

    /**
     * 获取用户唯一标识
     * 原因: CustomJdbcConnectionRepository中findUserIdsWithConnection() -->
     * if (localUserIds.size() == 0 && connectionSignUp != null) 判断数据库是否存在用户唯一标识和是否有ConnectionSignUp实现类 -->
     * 存在则自动注册
     * 用户首次登入数据库不保存用户信息,实现ConnectionSignUp满足自动注册得条件
     * @param connection
     * @return
     */
    @Override
    public String execute(Connection<?> connection) {
        return connection.getDisplayName();
    }
}


